/*
题目链接:https://leetcode.cn/problems/count-complete-subarrays-in-an-array/description/?envType=daily-question&envId=2025-04-24
*/

//题解代码:
class Solution {
public:
    int countCompleteSubarrays(vector<int>& nums) {
        int n = nums.size();
        unordered_map<int,int> ump;
        for(auto&x : nums)  ump[x]=true;
        int cnt = ump.size();
        ump.clear();
        int ans = 0;
        for(int l=0,r=0,s=0;r<n;++r){
            if(++ump[nums[r]] == 1) ++s;
            while(s == cnt){
                if(ump[nums[l]] == 1) break;
                ump[nums[l++]]--;
            }
            if(s==cnt) ans += l+1;
        }
        return ans;
    }
};
